/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */




//Vérification d'URL
function isUrl(s) {
    var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
    return regexp.test(s);
}

function isEmail(s){
    var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
    return reg.test(s)
}


//Avoir la couleur selon son id
function get_color(color_id) {
    var retour = "";
    var xhr;
    try {
        xhr = new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch (e) {
        try {
            xhr = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch (e2) {
            try {
                xhr = new XMLHttpRequest();
            }
            catch (e3) {
                xhr = false;
            }
        }
    } // fin du catch

   

    var url = "/jeu/bibli/db/couleurs.xml";
    xhr.open("GET", url, false);
    xhr.send(null);
    if (xhr.status == 200) {
        //document.getElementById("user_couleur").setAttribute("class", "cadre tarose");

        dct = xhr.responseXML;
        tab = dct.getElementsByTagName("color");
        nba = tab.length;



        erln1 = new RegExp(" ", "g");
        erln2 = new RegExp("(\n|\r)", "g");

        for (ide = 0; ide < tab.length; ide++) {


            var article = tab[ide]; // article courant
            //alert (color_id+' : '+article.attributes[0].value+' '+article.attributes[1].value+' '+article.attributes[2].value)
           // alert(color_id+' = '+article.attributes[0].value+' : '+article.attributes[1].value+' : '+article.attributes[2].value+' : ');
            if (article.attributes[0].value === color_id) {
             //   alert(article.attributes[2].value);
                return '#' + article.attributes[2].value.substring(2);
            }




        }

        
    }

}


//Savoir si un élément a une classe
function hasClass(element, cls) {
    return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1;
}